package systempen.cmanager;

import systempen.cmanager.R;
import systempen.cmanager.R.array;
import systempen.cmanager.R.layout;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


public class ReportList extends ListActivity {
	public Activity thisclass;
	private Context _contekst;
	public void onCreatee(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.splash);
		ThemePicker.onActivityCreateSetTheme(this);
		thisclass =  this;
		

	}

	@Override //pressed back button cya
	public boolean onKeyDown(int keyCode, KeyEvent event)  {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			startActivity(new Intent(getApplicationContext(), MainActivityTab.class)); 
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ThemePicker.onActivityCreateSetTheme(this);
		//setListAdapter(new ArrayAdapter<String>(this, R.layout.reportlist, COUNTRIES));
		String[] countries = getResources().getStringArray(R.array.reports_array);
		setListAdapter(new ArrayAdapter<String>(this, R.layout.reportlist, countries));

		ListView lv = getListView();
		lv.setTextFilterEnabled(true);
		_contekst = getParent();
		if(_contekst == null){
			_contekst = this;
		}

		lv.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// When clicked, show a toast with the TextView text
				//Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
				String menu = (String)((TextView) view).getText();
				if (menu.equals("List of costs in period")){
					try{
						//ReportList.this.startActivity(new Intent(getApplicationContext(), ReportAllByDateParams.class));
						Intent intent = new Intent();
						intent.setClass(_contekst, ReportAllByDateParams.class);
						ReportActivityStack activityStack = (ReportActivityStack) _contekst;
						activityStack.push("ReportAllByDateParams", intent);
					}
					catch(Exception ex) 
					{
						Toast.makeText(getApplicationContext(),"Reportlist: "+ex.getMessage(), Toast.LENGTH_LONG).show();
					}
				}
				if (menu.equals("Pie")){
					try{
						//ReportList.this.startActivity(new Intent(getApplicationContext(), ReportPieParams.class));
						Intent intent = new Intent();
						intent.setClass(_contekst, ReportPieParams.class);
						ReportActivityStack activityStack = (ReportActivityStack) _contekst;
						activityStack.push("ReportPieParams", intent);

					}
					catch(Exception ex) 
					{
						Toast.makeText(getApplicationContext(),"Reportlist: "+ex.getMessage(), Toast.LENGTH_LONG).show();
					}
				}
				if (menu.equals("Grouped list")){
					try{
						//ReportList.this.startActivity(new Intent(getApplicationContext(), ReportGroupedListParams.class));
						Intent intent = new Intent();
						intent.setClass(_contekst, ReportGroupedListParams.class);
						ReportActivityStack activityStack = (ReportActivityStack) _contekst;
						activityStack.push("ReportGroupedListParams", intent);
					}
					catch(Exception ex){
						Toast.makeText(getApplicationContext(),"Reportlist: "+ex.getMessage(), Toast.LENGTH_LONG).show();
					}
				}
				if (menu.equals("Daily list")){
					try{
						//ReportList.this.startActivity(new Intent(getApplicationContext(), ReportDailyListParams.class));
						Intent intent = new Intent();
						intent.setClass(_contekst, ReportDailyListParams.class);
						ReportActivityStack activityStack = (ReportActivityStack) _contekst;
						activityStack.push("ReportDailyListParams", intent);
					}
					catch(Exception ex){
						Toast.makeText(getApplicationContext(),"Daily List: "+ex.getMessage(), Toast.LENGTH_LONG).show();
					}
				}
				if (menu.equals("Pie comparasion graph")){
					try{
						//ReportList.this.startActivity(new Intent(getApplicationContext(), ReportDoublePieParams.class));
						Intent intent = new Intent();
						intent.setClass(_contekst, ReportDoublePieParams.class);
						ReportActivityStack activityStack = (ReportActivityStack) _contekst;
						activityStack.push("ReportDoublePieParams", intent);
					}
					catch(Exception ex){
						Toast.makeText(getApplicationContext(),"Pie comparasion graph: "+ex.getMessage(), Toast.LENGTH_LONG).show();
					}
				}
			}
		});
	}
}
